package com.jdiv;

import java.awt.Canvas;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.MemoryImageSource;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * @author  Joyal
 */
public class JWindow extends Frame{

private static final long serialVersionUID = -6581290592433058611L;

private boolean fullscreen=false;
private DisplayMode oldDisplayMode ;
private GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
private GraphicsDevice device = environment.getDefaultScreenDevice();
/**
 * @uml.property  name="panel"
 */
private Panel panel;

private int wWidth;

private int wHeight;

	public JWindow(){}
	public JWindow(String title,Canvas canvas,int width,int height){
		
		this.wWidth=width;
		this.wHeight=height;
		/*
		if (JDiv.scale>0){
		width=width*JDiv.scale;
		height=height*JDiv.scale;
		canvas.setSize(new Dimension(width,height));
		canvas.setPreferredSize(new Dimension(width,height));
		canvas.setBounds(0, 0, width, height);
		canvas.doLayout();
		}
		*/
		
		//setExtendedState(JFrame.MAXIMIZED_BOTH);
	
		setTitle(title+"-"+width+"x"+height);       //6,32
		//setSize(new Dimension(width,height));
		setSize(new Dimension(width+6,height+26)); //6,26
		//setSize(width+6,height+32);
		setResizable(false);
		setLayout(new BorderLayout());
		panel=new Panel();
	//	panel.setLayout(new BorderLayout());
		panel.setLayout(null);
			
		    addWindowListener( new WindowAdapter() {
	          public void windowClosing(WindowEvent e) {
	            System.exit(0);
	          }
	        });
	    
	   //Oculta el mouse
		    int[] pixels = new int[16 * 16];
		    Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
		    Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "invisibleCursor");
		    setCursor(transparentCursor);

		    
	    if (fullscreen){    
	//		 GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
	//		 GraphicsDevice device = environment.getDefaultScreenDevice();
			 DisplayMode displayMode = new DisplayMode(width, height, 32, 60);
		//	 DisplayMode displayMode = new DisplayMode(320, 240, 32, 60);
			 setUndecorated(true);
			 device.setFullScreenWindow(this);
			 device.setDisplayMode(displayMode);
			 validate();
			 
			 
	 }
	    canvas.setBounds(0, 0, width, height);
	// panel.add(canvas,BorderLayout.CENTER); 
	    

	   panel.add(canvas); 
		   
		add(panel,BorderLayout.CENTER);

	}
 

public void setFullScreen(boolean fullscreen){
	
	if (fullscreen){ 
		
		     setVisible(false); 
		  //   setUndecorated(true);
		     oldDisplayMode = device.getDisplayMode();
			 DisplayMode displayMode = new DisplayMode(wWidth, wHeight, 32, 60);
			 
			 
			 device.setFullScreenWindow(this);
			 device.setDisplayMode(displayMode);
			// validate();
			 setVisible(true); 
	  }else{
		  setVisible(false);
		  setUndecorated(false); 
		
		  device.setDisplayMode(oldDisplayMode);
		  device.setFullScreenWindow(null);
		  setVisible(true); 
	  }
	
}


public void close(){
		dispose();
	}
	
/**
 * @return
 * @uml.property  name="panel"
 */
public Panel getPanel(){
	return panel;
}
}

